package com.dy.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.dy.common.utils.bean.BeanUtils;
import com.dy.common.utils.poi.ExcelUtil;
import com.dy.system.domain.MedicalEquipmentReportLog;
import com.dy.system.domain.vo.DayHandleVo;
import com.dy.system.domain.vo.MedicalEquipmentReportLogVo;
import com.dy.system.service.IMedicalEquipmentReportLogService;
import com.github.pagehelper.PageHelper;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.dy.common.annotation.Log;
import com.dy.common.core.controller.BaseController;
import com.dy.common.core.domain.AjaxResult;
import com.dy.common.enums.BusinessType;
import com.dy.common.core.page.TableDataInfo;

/**
 * 设备上报日志Controller
 *
 * @author ruoyi
 * @date 2022-08-15
 */
@RestController
@RequestMapping("/system/log")
public class MedicalEquipmentReportLogController extends BaseController {
    @Autowired
    private IMedicalEquipmentReportLogService medicalEquipmentReportLogService;


    /***
     * 设备上报记录 applet
     * @param pageNo
     * @param pageSize
     * @return
     */
    @GetMapping("/report/log/list")
    public AjaxResult getEquipmentReportLogDataList(@RequestParam String code,@RequestParam Integer pageNo, @RequestParam Integer pageSize) {
        PageHelper.startPage(pageNo, pageSize);
        List<MedicalEquipmentReportLog> reportLogList = medicalEquipmentReportLogService.selectAppletMedicalEquipmentReportList(code);
        List<MedicalEquipmentReportLogVo> reportLogVos = BeanUtils.generatorList(reportLogList, MedicalEquipmentReportLogVo.class);
        return AjaxResult.success(reportLogVos);
    }

    /***
     * 设备日处理量 applet
     * @param pageNo
     * @param pageSize
     * @return
     */
    @GetMapping("/day/handle/list")
    public AjaxResult getDayHandleDataList(@RequestParam String code,@RequestParam Integer pageNo, @RequestParam Integer pageSize) {
        PageHelper.startPage(pageNo, pageSize);
        List<MedicalEquipmentReportLog> reportLogList = medicalEquipmentReportLogService.selectAppletMedicalEquipmentReportList(code);
        List<DayHandleVo> reportLogVos = BeanUtils.generatorList(reportLogList, DayHandleVo.class);
        return AjaxResult.success(reportLogVos);
    }







    /**
     * 查询设备上报日志列表
     */
    @PreAuthorize("@ss.hasPermi('system:log:list')")
    @GetMapping("/list")
    public TableDataInfo list(MedicalEquipmentReportLog medicalEquipmentReportLog) {

        startPageOrderBy("id desc");
        List<MedicalEquipmentReportLog> list = medicalEquipmentReportLogService.selectMedicalEquipmentReportLogList(medicalEquipmentReportLog);
        return getDataTable(list);
    }

    /**
     * 导出设备上报日志列表
     */
    @PreAuthorize("@ss.hasPermi('system:log:export')")
    @Log(title = "设备上报日志", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MedicalEquipmentReportLog medicalEquipmentReportLog) {
        List<MedicalEquipmentReportLog> list = medicalEquipmentReportLogService.selectMedicalEquipmentReportLogList(medicalEquipmentReportLog);
        ExcelUtil<MedicalEquipmentReportLog> util = new ExcelUtil<MedicalEquipmentReportLog>(MedicalEquipmentReportLog.class);
        util.exportExcel(response, list, "设备上报日志数据");
    }

    /**
     * 获取设备上报日志详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:log:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(medicalEquipmentReportLogService.selectMedicalEquipmentReportLogById(id));
    }

    /**
     * 新增设备上报日志
     */
    @PreAuthorize("@ss.hasPermi('system:log:add')")
    @Log(title = "设备上报日志", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MedicalEquipmentReportLog medicalEquipmentReportLog) {
        return toAjax(medicalEquipmentReportLogService.insertMedicalEquipmentReportLog(medicalEquipmentReportLog));
    }

    /**
     * 修改设备上报日志
     */
    @PreAuthorize("@ss.hasPermi('system:log:edit')")
    @Log(title = "设备上报日志", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MedicalEquipmentReportLog medicalEquipmentReportLog) {
        return toAjax(medicalEquipmentReportLogService.updateMedicalEquipmentReportLog(medicalEquipmentReportLog));
    }

    /**
     * 删除设备上报日志
     */
    @PreAuthorize("@ss.hasPermi('system:log:remove')")
    @Log(title = "设备上报日志", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(medicalEquipmentReportLogService.deleteMedicalEquipmentReportLogByIds(ids));
    }
}
